package com.huawei.appgallery.purchasehistory.ui.card;

import android.content.Context;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.TextView;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.purchasehistory.ui.bean.ConsumeRecordCardBean;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import o.cgz;
import o.chy;
import o.cst.a;
import o.cst.b;
import o.cst.e;
import o.cst.h;
import o.Logger;
import o.dof;

public class ConsumeRecordCard extends BaseDistCard {
    private View ʻ;
    private TextView ʼ;
    private TextView ʽ;
    protected Context ˋ;
    private TextView ॱॱ;
    private TextView ᐝ;

    public ConsumeRecordCard(Context context) {
        super(context);
        this.ˋ = context;
    }

    public cgz ˏ(View view) {
        this.ᐝ = (TextView) view.findViewById(e.ˏ);
        this.ʼ = (TextView) view.findViewById(e.ˎ);
        this.ॱॱ = (TextView) view.findViewById(e.ॱ);
        this.ʽ = (TextView) view.findViewById(e.ˋ);
        this.ʻ = view.findViewById(e.ʾ);
        ʽ(view);
        view.setBackgroundResource(b.ˋ);
        return this;
    }

    public void ॱ(final chy o_chy) {
        super.ॱ(o_chy);
        View ˉ = ˉ();
        if (ˉ != null) {
            ˉ.setOnLongClickListener(new OnLongClickListener(this) {
                final /* synthetic */ ConsumeRecordCard ˋ;

                public boolean onLongClick(View view) {
                    if (o_chy != null) {
                        o_chy.ˏ(-1, this.ˋ);
                    }
                    return true;
                }
            });
        }
    }

    public void ˏ(CardBean cardBean) {
        if (cardBean != null) {
            super.ˏ(cardBean);
            ConsumeRecordCardBean consumeRecordCardBean = (ConsumeRecordCardBean) cardBean;
            ˊ(consumeRecordCardBean);
            ˏ(consumeRecordCardBean);
            ˎ(consumeRecordCardBean);
            ˋ(consumeRecordCardBean);
            this.ʻ.setVisibility(ˊᐝ() ? 0 : 8);
        }
    }

    private void ˊ(ConsumeRecordCardBean consumeRecordCardBean) {
        if (!dof.ॱ(consumeRecordCardBean.ᶥ())) {
            if (dof.ॱ(consumeRecordCardBean.ʽ())) {
                this.ᐝ.setText(consumeRecordCardBean.ᶥ());
            } else {
                this.ᐝ.setText(consumeRecordCardBean.ʽ() + HwAccountConstants.BLANK + "-" + HwAccountConstants.BLANK + consumeRecordCardBean.ᶥ());
            }
            this.ᐝ.setVisibility(0);
        } else if (dof.ॱ(consumeRecordCardBean.ʽ())) {
            this.ᐝ.setVisibility(4);
        } else {
            this.ᐝ.setText(consumeRecordCardBean.ʽ());
            this.ᐝ.setVisibility(0);
        }
    }

    private void ˎ(ConsumeRecordCardBean consumeRecordCardBean) {
        if (consumeRecordCardBean.ꓸ() == null || consumeRecordCardBean.ꓸ().isEmpty()) {
            this.ॱॱ.setVisibility(4);
            return;
        }
        this.ॱॱ.setText(consumeRecordCardBean.ꓸ().replace('￥', '¥'));
        this.ॱॱ.setVisibility(0);
    }

    private void ˋ(ConsumeRecordCardBean consumeRecordCardBean) {
        if (!dof.ॱ(consumeRecordCardBean.ꜞ())) {
            this.ʽ.setTextColor(this.ˋ.getResources().getColor(a.ˎ));
            String replace = consumeRecordCardBean.ꜞ().replace('￥', '¥');
            this.ʽ.setText(this.ˋ.getString(h.ʻ, new Object[]{replace}));
            this.ʽ.setVisibility(0);
        } else if (consumeRecordCardBean.ˊ() == null || consumeRecordCardBean.ˊ().isEmpty()) {
            this.ʽ.setVisibility(4);
        } else {
            this.ʽ.setText(consumeRecordCardBean.ˊ());
            this.ʽ.setTextColor(this.ˋ.getResources().getColor(a.ˋ));
            this.ʽ.setVisibility(0);
        }
    }

    void ˏ(ConsumeRecordCardBean consumeRecordCardBean) {
        if (TextUtils.isEmpty(consumeRecordCardBean.ॱ())) {
            this.ʼ.setVisibility(4);
            return;
        }
        this.ʼ.setText(ˏ(consumeRecordCardBean.ॱ()));
        this.ʼ.setVisibility(0);
    }

    private String ˏ(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        try {
            if (TextUtils.isEmpty(str)) {
                return "";
            }
            return DateUtils.formatDateTime(this.ˋ, simpleDateFormat.parse(str).getTime(), 131092);
        } catch (ParseException e) {
            Logger.e("ConsumeRecordCard", e.toString());
            return null;
        }
    }
}
